<?php
/*
 * description：
 * author：wh
 * email：
 * createTime：{2023/1/21} {16:22} 
 */

namespace app\index\controller;


use app\apidata\Config;
use app\common\model\TabConf;
use think\Controller;
use think\Db;
use think\Request;
use wanghua\general_utility_tools_php\framework\BaseController;
use wanghua\general_utility_tools_php\tool\Tools;

class BaseCommonController extends BaseController
{

    /**
     * desc：检查路径维护状态
     *
     * “===”完全匹配，不能使用like
     *
     * author：wh
     */
    protected function checkMaintain(){

        $configs = Db::table(TabConf::$fa_sys_maintain_config)
            ->where('status','1')
            ->cache()
            ->select();

        //模块
        $strmodule = request()->module();
        foreach ($configs as $config){
            if($strmodule == $config['url']){
                //模块维护中
                return ['is_maintain'=>true,'msg'=>$config['msg'],'openid'=>$config['openid']];
            }
        }

        //模块/控制器
        $strcontroller = strtolower(request()->module().'/'.request()->controller());
        foreach ($configs as $config){
            if($strcontroller == $config['url']){
                //模块维护中
                return ['is_maintain'=>true,'msg'=>$config['msg'],'openid'=>$config['openid']];
            }
        }

        //模块/控制器/方法
        $straction = strtolower(request()->module().'/'.request()->controller().'/'.request()->action());
        foreach ($configs as $config){
            if($straction == $config['url']){
                //模块维护中
                return ['is_maintain'=>true,'msg'=>$config['msg'],'openid'=>$config['openid']];
            }
        }

        //未维护
        return ['is_maintain'=>false,'msg'=>'服务运行中'];
    }
}